<hr>
<?php 
$FORMURL = "{URL}/{page}/{nextaction}";
$formidentifier = "add";
	if($action == "edit" || $action == "edit2"){
		$FORMURL .= "/".($record['id']);
		$formidentifier = $record['id'];
	}else if($action == "update"){
		$FORMURL .= "/{ID}";
		$formidentifier = "{ID}";
	}
?>
<form action="<?=$FORMURL;?>" method="post" enctype="multipart/form-data" id="form_{page}_<?=$formidentifier?>">
	<font color ="red" id="error_message_{page}_<?=$formidentifier?>"><?=validation_errors();?></font>
	<table>
		<?php
			forEach($fields[DATA] as $field)
		    {
		      $_type = $field[TYPE];
		      $_label = $field[LABEL];
		      $_field = $field[FIELDS];
		      $_required = (isset($field[REQUIRED])) && $field[REQUIRED];
		      
		      if($action == "insert" || $action == "update")
		      	 $_value = set_value($field[FIELDS]); // (isset($record[$fields[FIELDS][$x][FIELDS]] ) ? $record[$fields[FIELDS][$x][FIELDS]] : "" );
		      else
				 $_value = (isset($record[$field[FIELDS]] ) ? $record[$field[FIELDS]] : "" );
			 
		      
		      echo "<tr><td valign='top'>$_label";
			  echo "</td><td>";
			  if($_type == "")
			  	$_type = "textbox";
			  include TAGS."$_type.php";
			  	if($_required){
			  		echo "<b> *</b>";
			  	}
			  
			  echo "</td><tr>";
			}
		 ?>
		 <?php if(!isset($skipEndForm) ):?>
		 <tr>
		 	<td>
		 		<input type="submit" name="submit" value="Save">
		 	</td>
		 	<td><input type="reset" value="Cancel" onclick="cancelAction(this , '{page}', '<?=$formidentifier?>');"></td>
		 </tr>
		 <?php endif;?>
	</table>
	<?php if(!isset($skipEndForm) ):?>
		</form>
		<hr>
	<?php endif;?>